package refactorplugin.views;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class CoreError implements INotificationObject {
	
	private List<Exception> _eList = new LinkedList<Exception>();
	
	public void addError(Exception e) {
		_eList.add(e);
	}

	@Override
	public void show(ColumnViewer viewer) {
		System.out.println("CoreError>Operate");
		TableViewer tableViewer = (TableViewer)viewer; 
		if (tableViewer!=null) {
			tableViewer.getTable().clearAll();
			System.out.println("CoreError>clearAll");
			tableViewer.setInput(_eList);
			tableViewer.refresh();
		} else
			System.out.println("TaskTreeRows>Viewer = null");
		
		/*System.out.println("CoreError>Operate");
		Display display = viewer.getControl().getDisplay();
		final Shell shell = new Shell(display );
		shell.setText("Error");
		Label error = new Label(shell,SWT.WRAP);
		Color c = new Color(display, 200, 28, 28);
		error.setForeground(c);
		String errorLines = null;
		for (Exception e:_eList)
			errorLines+=e.getMessage()+"\n";
		error.setText(_eList.toString());//errorLines);
		error.pack();
		shell.pack();
		shell.open ();*/
	}
	
	public boolean isEmpty() {
		return _eList.isEmpty();
	}

	@Override
	public boolean isTable() {
		return true;
	}

}
